﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.SYS
{
    public partial class user_role_edit : PageBase
    {

        string sid = "";
        public string us;
        public BLL.SC.zhongjie jbs = new BLL.SC.zhongjie();

        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();

            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["sid"]))
                {
                    sid = Request["sid"].Trim();

                    hidsid.Text = sid;
                    fill();
                }
             
            }

        }

        void fill()
        {
            //用户
            DataTable e = BLL.Bllbase.get_table("[sys_user]");
            ddlperson.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlperson.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["user_name"].ToString().Trim(), e.Rows[i]["sbh"].ToString().Trim()));
            }
            ddlperson.DataBind();

            //角色
            e = BLL.Bllbase.get_table("[menu_safe]");
            ddlmenu.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlmenu.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["bname"].ToString().Trim(), e.Rows[i]["sid"].ToString().Trim()));
            }
            ddlmenu.DataBind();


            DataTable d = BLL.sys.sys_safe.getlist("user_safe", "sid=" + sid + "");

            //行业分类
            ddlperson.SelectedIndex = ddlperson.Items.IndexOf(ddlperson.Items.FindByValue(d.Rows[0]["ubh"].ToString()));
            ddlmenu.SelectedIndex = ddlmenu.Items.IndexOf(ddlmenu.Items.FindByText(d.Rows[0]["mname"].ToString()));
         


        }
       
   


      
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
           
            string sid =hidsid.Text;
           
            
            if (sid == "") return;


            string ubh = ddlperson.SelectedValue;
            string uname = ddlperson.SelectedText;
            string mm = ddlmenu.SelectedText;
            string menu = ddlmenu.SelectedValue;

            DAL.DbHelperSQL.ExecuteNonQuery("update user_safe set ubh='" + ubh + 
                "',uname='" + uname + "',mname='" + mm + "',menu='" + menu + "' where sid="+sid+"");


            Alert.Show("修改完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
       
        }

       
    }
}